<template>
	<div>
		<el-popover placement="bottom" trigger="hover" v-if="(permissionRename()||permissionMove()||permissionDel()||permissionSave() || permissionEnclosure())&&(treeData.data.dirType!='00'||treeData.data.dirLevel!=0)&&(treeData.data.dirType!='02'||treeData.data.dirLevel!=0)">
			<div class="popover-content">
				<div class="popover-content-top" v-if="treeData.data.dirLevel > 0 && (permissionRename()||permissionMove()||permissionDel())">
					<span class="popover-content-top-title" v-if="permissionRename()" @click="loadRename">重命名</span>
<!--					<span class="popover-content-top-title" v-if="permissionMove()"  @click="loadMove(treeData)">移动</span>-->
					<span class="popover-content-top-title" v-if="permissionDel()" @click="loadDel">删除</span>
				</div>
				<div :class="[treeData.data.dirLevel > 0?'popover-content-bottom':'']"   v-if="(permissionSave() || permissionEnclosure())&&(treeData.data.dirType!='00'&&treeData.data.dirType!='02')">
					<!-- <span class="popover-content-top-title"  v-if="permissionSave()"  @click="loadFolder(treeData.data)">新建文件夹</span> -->
					<span class="popover-content-top-title"  v-if="permissionSave()"  @click="loadFolder('文件夹')">新建文件夹</span>
<!--					<singlefileUpload ref="upload" @uploadSave="uploadSave" v-if="permissionEnclosure()">-->
<!--						<template v-slot:openDialog>-->
<!--							<span class="popover-content-top-title">上传附件</span>-->
<!--						</template>-->
<!--					</singlefileUpload>-->
				</div>
			</div>
			<i slot="reference" class="document-left-tree-more el-icon-more"></i>
		</el-popover>
		<!-- 重命名 -->
		<rename ref="renames" :treeData="treeData" @updateTree="updateTree"></rename>
		<!-- 移动 -->
		<move ref="move" @updateTree="updateTree" :dircontract='dircontractadd'></move>
		<!-- 删除 -->
		<del-contnet ref="del" :treeData="treeData" @updateTree="updateTree"></del-contnet>
		<!-- 新建文件夹 -->
		<folder ref="folder" :treeData="treeData" @updateTree="updateTree"></folder>
		<!-- 上传列表 -->
		<!-- <uploadList style="z-index: 99999;" v-if="uploadForm.length > 0 && uploadListType == true" :uploadForm="uploadForm" @uploadListDel="uploadListDel"></uploadList> -->
	</div>
</template>

<script>
	import folder from './folder.vue'
	import evclosure from './evclosure.vue'
	import rename from './rename.vue'
	import move from './move.vue'
	import delContnet from './del.vue'
	import singlefileUpload from "../../../../components/upload/singlefileUpload";
	import uploadList from "../../../../components/upload/uploadList.vue"
	import {
		save
	} from '@/api/doc.js'
  import permissionFunc from "../../../../utils/permission";
	export default {
		data() {
			return {
				delVisible: false,
				uploadListType: false,
				uploadForm: [],
				dircontractadd:null
			}
		},
		components: {
			folder,
			evclosure,
			rename,
			move,
			delContnet,
			singlefileUpload,
			uploadList
		},
		props: [
			'treeData','dircontract'
		],
		created() {
			this.dircontractadd=this.dircontract
      // this.popoverClick()
		},
		methods: {
      permissionRename(){
		    console.log(this.treeData.data.dirType)
		    console.log(permissionFunc.inserted(['task:form:save']))
        console.log('权限权限')
        if(this.treeData.data.dirType == '05'){
          if(permissionFunc.inserted(['dir:form:edit'])&& permissionFunc.inserted(['contract:form:edit'])){
            return true
          }else {
            return  false
          }
        }else {
          return permissionFunc.inserted(['dir:form:edit'])
        }
      },
      permissionMove(){
        if(this.treeData.data.dirType == '05'){
          if(permissionFunc.inserted(['dir:form:move'])&& permissionFunc.inserted(['contract:form:move'])){
            return true
          }else {
            return  false
          }
        }else {
          return permissionFunc.inserted(['dir:form:move'])
        }
      },
      permissionDel(){
        if(this.treeData.data.dirType == '05'){
          if(permissionFunc.inserted(['dir:form:del'])&& permissionFunc.inserted(['contract:form:del'])){
            return true
          }else {
            return  false
          }
        }else {
          return permissionFunc.inserted(['dir:form:del'])
        }
      },
      permissionSave(){
        if(this.treeData.data.dirType == '05'){
          if(permissionFunc.inserted(['dir:form:save'])&& permissionFunc.inserted(['contract:form:save'])){
            return true
          }else {
            return  false
          }
        }else {
          return permissionFunc.inserted(['dir:form:save'])
        }
      },
      permissionEnclosure(){
        if(this.treeData.data.dirType == '04' && permissionFunc.inserted(['dir:form:save'])){
          return true
        }else {
          return false
        }
      },
			// 更新树节点
			updateTree(data) {
				console.log(data)
				this.$emit('updateTree', data)
			},
			// 移动分支
			loadMove(data) {
				this.$refs.move.loadMove(data)
			},
			// 修改文件名
			loadRename() {
				this.$refs.renames.loadRename()
			},
			// 删除分支
			loadDel() {
				this.$refs.del.loadDel()
			},
			// loadEnclosure() {
			// 	this.$refs.evclosure.loadEnclosure()
			// },
			loadFolder(data) {
				// console.log(data);
				this.$refs.folder.loadFolder(data)
			},
			uploadSave(val) {
				let _this = this
				var docFilePath = [{
					fileUrl : val.url,
					fileName: val.name
				}]
				let data = {
					name: val.name,
					docFilePath: docFilePath,
					docType: '04',
					dirId: _this.treeData.data.dirId,
					status: '00'
				}
				save(data).then(res => {
					console.log(data)
					var docForm = {
						data: {},
						type: 'save'
					}
					_this.$EventBus.$emit('updateDoc', docForm)
					_this.$refs.upload.sucessClick()
				})
			},
		}
	}
</script>

<style scoped>
	.popover-content {}

	.popover-content-top {
		/*padding-bottom: 10px;*/
		/*border-bottom: 1px solid #e3e9ed;*/
	}

	.popover-content-top-title {
		color: #2e405e;
		font-size: 14px;
		display: block;
		width: 100%;
		padding-top: 10px;
		padding-bottom: 10px;
		padding-left: 10px;
		padding-right: 10px;
	}

	.popover-content-top-title:hover {
		background-color: #f5f6f8;
	}

	.popover-content-bottom {
		/* padding-top: 10px; */
	}


	.document-left-tree-more {
		font-size: 12px;
	}

	/deep/.el-popover {
		padding: 0;
	}

	/deep/.el-dialog .el-dialog__footer {
		border-color: white;
	}

	/deep/.el-dialog__title {
		font-weight: bold;
		font-size: 16px;
	}
</style>
